@extends("admin.common.admin")
<title>用户管理</title>
@section("cnt")
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        首页
        <span class="c-gray en">&gt;</span>
        用户管理列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <div class="page-container">
        @include("admin.common.msg")
        <form action="{{ route("admin.admin.user") }}" method="get">
            <div class="text-c"> 日期范围：
                <input type="text" value="{{ request()->get("datemax") }}" name="datemax" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}' })" id="datemin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" value="{{ request()->get("datemin") }}" name="datemin" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" value="{{ request()->get("username") }}" class="input-text" style="width:250px" placeholder="输入会员名称、电话、邮箱" id="" name="username">
                <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
            </div>
        </form>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            {!! $fangowner->addBtn("admin.fangowner.create","添加用户") !!}
            <a href="{{ route('admin.fangowner.excel') }}" class="btn btn-success radius">
				    <i class="Hui-iconfont">&#xe644;</i> 导出Excel数据
		    </a>
             <a href="/uploads/excel/fangdong-{{ date("Y-m-d") }}.xlsx" class="btn btn-success">
                <i class="Hui-iconfont">&#xe644;</i> 下载Excel数据
            </a>
        </span>
            <span class="r">共有数据：
            <strong>{{ $data->total() }}</strong> 条
        </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="25"><input type="checkbox" name="" value=""></th>
                    <th width="80">ID</th>
                    <th width="100">房东姓名</th>
                    <th width="100">年龄</th>
                    <th width="100">身份证</th>
                    <th width="100">家庭住址</th>
                    <th width="40">性别</th>
                    <th width="90">手机</th>
                    <th width="150">邮箱</th>
                    <th width="130">加入时间</th>
                    <th width="70">状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr class="text-c">
                        <td><input type="checkbox" value="{{ $item->id }}" name="id[]"></td>
                        <td>{{ $item->id }}</td>
                        <td>{{ $item->name }}</td>
                        <td>{{ $item->age }}</td>
                        <td>{{ $item->card }}</td>
                        <td>{{ $item->address }}</td>
                        <td>{{ $item->sex }}</td>
                        <td>{{ $item->phone }}</td>
                        <td>{{ $item->email }}</td>
                        <td>{{ $item->created_at }}</td>
                        <td class="td-status">
                            @if(!$item->deleted_at)
                                <span class="label label-success radius">已启用</span>
                            @else
                                <span class="label label-danger radius">禁用</span>
                            @endif
                        </td>
                        <td class="td-manage">
                            {!! $fangowner->editBtn("admin.fangowner.edit","修改",["id" => $item->id]) !!}
                            {!! $fangowner->showBtn("admin.fangowner.show","查看",["id" => $item->id]) !!}
                            {!! $fangowner->deleteBtn("admin.fangowner.destroy","删除",["id" => $item->id]) !!}
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->appends(request()->except("page"))->links() }}
        </div>
    </div>
@endsection
@section("js")
    <script>
        function datadel() {
            // 定义一个空的变量
            let id = [];
            // 获取到id
            let inplist = $("input[name='id[]']:checked");
            // console.log(inp)
            if(inplist.length>0){
                $.each(inplist,(key,item)=>{
                    id.push(Number($(item).val()));
                })
                if(id.length>0){
                    layer.confirm('确认删除该页面的全部用户吗？', {
                        btn: ['确认','取消'] //按钮
                    }, ()=> {
                        $.get("{{ route("admin.admin.deleteAll") }}",{id}).then(ret => {
                            layer.msg(ret.msg, {icon: 1,time: 2000},()=>{
                                if(ret.status == 200){
                                    location.reload();
                                }

                            });
                        })
                    });
                }
            }
        };
        $(function () {
            $(".del").click(function () {
                // let href = ;
                layer.confirm('确认删除该用户吗？', {
                    btn: ['确认','取消'] //按钮
                }, ()=>{
                    $.ajax({
                        url : $(this).attr("href"),
                        type : "delete",
                        data :{
                            _token:"{{ csrf_token() }}"
                        }
                    }).then(ret => {
                        // console.log(ret);
                        layer.msg(ret.msg, {icon: 1,time: 2000},()=>{
                            if(ret.status == 200){
                                $(this).parents("tr").remove();
                            }

                        });
                    });

                });


                return false;
            });
        })

    </script>
@endsection
